//
//  FeedbackReplyView.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/6/22.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "FeedbackReplyView.h"

@interface FeedbackReplyCell : UITableViewCell

@property (nonatomic, strong) UILabel *replyTitleLab;
@property (nonatomic, strong) UILabel *replyTimeLab;
@property (nonatomic, strong) UILabel *replyContentLab;

@property (nonatomic, strong) FeedbackReplyEntity *entity;

@end

@implementation FeedbackReplyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupSubViews];
    }
    return self;
}

- (void)setupSubViews
{
    self.backgroundColor = kColorF5F5F5;
    
    self.replyTitleLab = [[UILabel alloc] init];
    self.replyTitleLab.textColor = kColorFF6B6B;
    self.replyTitleLab.font = [UIFont systemFontOfSize:13];
    self.replyTitleLab.text = @"商户回复:";
    [self addSubview:self.replyTitleLab];
    
    self.replyTimeLab = [[UILabel alloc] init];
    self.replyTimeLab.textColor = kColorFF6B6B;
    self.replyTimeLab.font = [UIFont systemFontOfSize:13];
    [self addSubview:self.replyTimeLab];
    
    self.replyContentLab = [[UILabel alloc] init];
    self.replyContentLab.textColor = kColorFF6B6B;
    self.replyContentLab.font = [UIFont systemFontOfSize:13];
    self.replyContentLab.numberOfLines = 0;
    [self addSubview:self.replyContentLab];
    
    [self.replyTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.top.equalTo(self).offset(13);
    }];
    
    [self.replyTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-11);
        make.centerY.equalTo(self.replyTitleLab);
    }];
    
    [self.replyContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.replyTitleLab);
        make.top.equalTo(self.replyTitleLab.mas_bottom).offset(12);
        make.right.equalTo(self.replyTimeLab);
        make.bottom.equalTo(self).offset(-16);
    }];
    
    
    
}

- (void)setEntity:(FeedbackReplyEntity *)entity
{
    _entity = entity;
    self.replyTimeLab.text = entity.updateTime;
    self.replyContentLab.text = entity.replyContent;
}


@end

@interface FeedbackReplyView ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;


@end

@implementation FeedbackReplyView

- (void)setupSubViews
{
    self.backgroundColor = kColorF5F5F5;
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.scrollEnabled = false;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [self.tableView registerClass:[FeedbackReplyCell class] forCellReuseIdentifier:@"FeedbackReplyCell"];
    
}

- (void)setReplyList:(NSArray<FeedbackReplyEntity *> *)replyList
{
    _replyList = replyList;
    CGFloat h = 0;
    for (FeedbackReplyEntity *entity in replyList) {
        h += entity.rowHeight;
    }
    self.tableView.frame = CGRectMake(0, 0, self.bounds.size.width, h);
    [self.tableView reloadData];
}


#pragma mark - UITableViewDataSource,UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.replyList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FeedbackReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FeedbackReplyCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.entity = self.replyList[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.replyList[indexPath.row].rowHeight;
}

@end
